<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Tìm nhanh</title>
    <link rel="stylesheet" href="css/reset.css" type="text/css" />
	<link rel="stylesheet" href="css/common.css" type="text/css" /> 
	<link rel="stylesheet" href="css/sign-up.css" type="text/css" />
    
	<script src="scripts/jquery-1.5.2.min.js"></script>
	<script src="scripts/common.js"></script>
	<script type="text/javascript">
		var xmlhttp;
		function createXMLHTTPRequest()
		{
			if(window.XMLHttpRequest)
			{
				return new XMLHttpRequest();
			}
			else if(window.ActiveXObject)
			{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
        function btnSearch_Click()
		{
			var key=document.getElementById("txtKey").value;
			var type=document.getElementById("selectid").value;
			var serverUrl;
			if(type==1)
			{
				serverUrl="DAO/FastSearchProductDAO.php?key="+key+"&type=0";
			}
			else if(type==2)
			{
				serverUrl="DAO/FastSearchDepartmentDAO.php?key="+key+"&type=0";
			}			
			xmlhttp=createXMLHTTPRequest();
			xmlhttp.onreadystatechange=showFastSearchProduct;
			xmlhttp.open("get",serverUrl,true);
			xmlhttp.send(null);		

		}
		function showFastSearchProduct()
		{
			if(xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var div=document.getElementById("divResult");
				div.innerHTML=xmlhttp.responseText;
				
			}
		}
		function indexClick(i)
		{
		
			var key=document.getElementById("keyhd").value;
			var type=document.getElementById("typehd").value;
			var serverUrl;
			
			serverUrl="DAO/FastSearchProductDAO.php?key="+key+"&type="+type+"&page="+i;
					
			xmlhttp=createXMLHTTPRequest();
			xmlhttp.onreadystatechange=showFastSearchProduct;
			xmlhttp.open("get",serverUrl,true);
			xmlhttp.send(null);	
		}
		function indexClickgh(i)
		{
			var key=document.getElementById("keyhd").value;
			var type=document.getElementById("typehd").value;
			var serverUrl;
			
			serverUrl="DAO/FastSearchDepartmentDAO.php?key="+key+"&type="+type+"&page="+i;
					
			xmlhttp=createXMLHTTPRequest();
			xmlhttp.onreadystatechange=showFastSearchProduct;
			xmlhttp.open("get",serverUrl,true);
			xmlhttp.send(null);	
		}
		function cbChange()
		{
			var key=document.getElementById("keyhd").value;
			var type=document.getElementById("slid").value;
			/*alert(type);*/
			var serverUrl;
			
			serverUrl="DAO/FastSearchProductDAO.php?key="+key+"&type="+type;
					
			xmlhttp=createXMLHTTPRequest();
			xmlhttp.onreadystatechange=showFastSearchProduct;
			xmlhttp.open("get",serverUrl,true);
			xmlhttp.send(null);	
		}
		function cbChangegh()
		{
			var key=document.getElementById("keyhd").value;
			var type=document.getElementById("slid").value;
			/*alert(type);*/
			var serverUrl;
			
			serverUrl="DAO/FastSearchDepartmentDAO.php?key="+key+"&type="+type;
					
			xmlhttp=createXMLHTTPRequest();
			xmlhttp.onreadystatechange=showFastSearchProduct;
			xmlhttp.open("get",serverUrl,true);
			xmlhttp.send(null);	
		}
		function loadPage(type,key)
		{
			var serverUrl;
			if(type==1)
			{
				serverUrl="DAO/FastSearchProductDAO.php?key="+key+"&type=0";
			}
			else if(type==2)
			{
				serverUrl="DAO/FastSearchDepartmentDAO.php?key="+key+"&type=0";
			}	
			
					
			xmlhttp=createXMLHTTPRequest();
			xmlhttp.onreadystatechange=showFastSearchProduct;
			xmlhttp.open("get",serverUrl,true);
			xmlhttp.send(null);	
		}
    </script>
</head>

<body>
	<?php
		if(isset($_REQUEST["key"]))
		{
			$key=$_REQUEST["key"];
			$type=$_REQUEST["type"];
			echo("<script type='text/javascript' language='javascript'>
			loadPage($type,$key);
			</script>");
		}
	?>
    <div id="page">
        <?php
			include_once("webconfig.php");
			include_once("DAO/DataHelper.php");
			include_once("DAO/DanhMucSanPham_DAO.php");
			include_once("DAO/SanPham_DAO.php");
            require("UserControl/header1.php");
        ?>
       <div id="content">
		<?php
			require("UserControl/DanhMucLoaiSanPham.php");
		?>
          <div id="hot-seller" class="block layout-3col-col2">
              <div class="title"><h4>Tìm kiếm nhanh</h4></div>
              <div class="content">
                  <table>
                      <tbody>
                          <tr>
                              <td>
                                  <label>Từ khóa</label>
                                  <input type="text" id="txtKey"  />
                                  <label>Bạn muốn tìm :</label>
                                  <select id="selectid">
                                      <option value="1" >sản phẩm
                                      </option>
                                      <option value="2">gian hàng
                                      </option>
                                  </select>
                                  <input type="button" value="Tìm" onclick="btnSearch_Click();" />
                              </td>
                          </tr>
                      </tbody>
                  </table>
               
					<div id="divResult" align="center">
					</div>	
				</div>
			</div>
			<?php
				require("UserControl/DanhSachSanPhamBanChay.php");	
			?>
		</div>
      
        <?php
            require("UserControl/Footer.php");
        ?>
     </div>
</body>
</html>